﻿
namespace ExDUIR.NET.Color
{
    public class ExARGB
    {
        public byte A { get; }
        public byte R { get; }
        public byte G { get; }
        public byte B { get; }

        // 从32位整数构造
        public ExARGB(int argb)
        {
            A = (byte)((argb >> 24) & 0xFF);
            R = (byte)((argb >> 16) & 0xFF);
            G = (byte)((argb >> 8) & 0xFF);
            B = (byte)(argb & 0xFF);
        }

        // 从分量构造
        public ExARGB(byte r, byte g, byte b, byte a)
        {
            A = a;
            R = r;
            G = g;
            B = b;
        }

        // 转换为32位整数
        public int ToInt32() => (A << 24) | (R << 16) | (G << 8) | B;

        // 静态构造方法
        public static ExARGB FromRGB(byte r, byte g, byte b) => new ExARGB(255, r, g, b);
        public static ExARGB FromARGB(byte a, byte r, byte g, byte b) => new ExARGB(a, r, g, b);

        // 从现有RGB值添加Alpha通道
        public static ExARGB FromRGBWithAlpha(int rgb, byte alpha) => new ExARGB(
            alpha,
            (byte)((rgb >> 16) & 0xFF),
            (byte)((rgb >> 8) & 0xFF),
            (byte)(rgb & 0xFF)
        );

        // 修改Alpha通道（返回新对象）
        public ExARGB WithAlpha(byte alpha) => new ExARGB(alpha, R, G, B);

        // 运算符重载
        public static implicit operator int(ExARGB argb) => argb.ToInt32();
        public static implicit operator ExARGB(int argb) => new ExARGB(argb);

        public override string ToString() => $"A: {A}, R: {R}, G: {G}, B: {B}";
    }
}
